<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Removing and Renaming Objects</title>
    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
    <link rel="start" href="index.html" title="Getting Started with Distributed Berkeley DB Applications" />
    <link rel="up" href="client.html" title="Chapter 3. Berkeley DB Client Driver APIs" />
    <link rel="prev" href="client.admin_api.html" title="Administrative Functions" />
    <link rel="next" href="client.bulk_api.html" title="Key/Data Pairs and Bulk Operations" />
  </head>
  <body>
    <div xmlns="" class="navheader">
      <div class="libver">
        <p>Library Version 12.1.6.2</p>
      </div>
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">Removing and Renaming Objects</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="client.admin_api.html">Prev</a> </td>
          <th width="60%" align="center">Chapter 3. Berkeley DB Client Driver APIs</th>
          <td width="20%" align="right"> <a accesskey="n" href="client.bulk_api.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title" style="clear: both"><a id="client.resource_api"></a>Removing and Renaming Objects</h2>
          </div>
        </div>
      </div>
      <p> 
            Operations that remove or rename an environment, a database or a
            sequence object require care. First, operations on the same object
            must be serialized. For example, you cannot rename and remove a
            database simultaneously. Second, they cannot be performed if there
            are still open handles on the object. To solve the first issue,
            operations on the same objects are serialized explicitly by the
            server program. To solve the second issue, the driver APIs for these
            operations behave slightly differently from the <span>Java base</span> APIs. 
        </p>
      <p> 
            In the driver APIs, each of these functions has a boolean
            argument <code class="literal">force</code>. If this argument is set to
            <code class="literal">true</code>, all handles opened on the object to be
            removed or renamed are automatically closed by the server, so the
            operation can proceed. If this argument is set to
            <code class="literal">false</code>, the operation is executed only if
            there is no open handle on the object; otherwise, the function
            throws a <span><code class="classname">SResourceInUseException</code>
            exception.</span>
        </p>
      <p>
            For example, if you want to remove a database even if someone is
            still using it, you can call <span>
            <code class="classname">SEnvironment.removeDatabase</code>
            </span> with the <code class="literal">force</code> parameter set to
            <code class="literal">true</code>: 
        </p>
      <pre class="programlisting">BdbServerConnection conn = ...;
SEnvironment env = conn.openEnvironment("env", null);

// Force the database to be deleted.
env.removeDatabase(null, "db", null, true);</pre>
      <p>
            If you want to remove a database, but only when no one is using
            it, you can call the same function with the <code class="literal">force</code>
            parameter set to <code class="literal">false</code>: 
        </p>
      <pre class="programlisting">BdbServerConnection conn = ...;
SEnvironment env = conn.openEnvironment("env", null);
<strong class="userinput"><code>
try {
    // Try to remove the database if no one is using it.
    env.removeDatabase(null, "db", null, false);
    // The database is removed successfully.
} catch (SResourceInUseException e) {
    // Someone is still using the database and the database
    // is not removed
}
</code></strong></pre>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="client.admin_api.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="client.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="client.bulk_api.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">Administrative Functions </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> Key/Data Pairs and Bulk Operations</td>
        </tr>
      </table>
    </div>
  </body>
</html>
